<?php
Class Personnel{
	public $nom;
	public $prénom;
	public $TelPrive;
	public $TelPublic;
	public $Id_service;
	public $Id_UFR;
	public $Id_fonction;
	public $bureau;
	public $Email;
	public $site;
	public $BDD;
	
	function __tostring() {
    	return "Cette classe permet g�rer le Personnel.<br/>";
    }
	function __construct($objSite,$Site) {
		$this->site = $objSite;	
        $this->BDD=$Site;
	}
	function login($login,$mdp){
		if( $login!="" && $mdp!=""){
			$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='Login']";
		    $Q=$this->site->XmlParam->GetElements($Xpath);        
		    $where=str_replace("-login-",$login,$Q[0]->where);
		    $where=str_replace("-mdp-",$mdp,$where);
		   	$sql=$Q[0]->select.$Q[0]->from.$where;
		   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
		   	$l=$db->connect();
		   	$req = $db->query($sql);
		   	$result=(mysql_fetch_assoc($req));
		   	$db->close($l);
		    if($result['id_admin']!=''){
		     $_SESSION['sessLogin']=$login;
		     $_SESSION['sessDroit']=$result['droits'];
	         $msg='';
		   }else{
		   	 INCLUDE(PathWeb.'Login.php');
		   	 $msg='Login ou Mot de passe incorrecte';
		   	 exit;
		   }
	  }else
	  	 $msg='Il faut saisir le login et le mot de passe';
	}
	
	function getListePerso($lettre){
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='getListePerso']";
		$Q=$this->site->XmlParam->GetElements($Xpath);     
	    $where=str_replace("-MinLettre-",strtolower($lettre),$Q[0]->where);
	    $where=str_replace("-MajLettre-",$lettre,$where);
	   	$sql=$Q[0]->select.$Q[0]->from.$where;
	   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	   	$req = $db->query($sql);
	   	$db->close($link);
	   	return $req; 
	}
	function TrFonctionsPreso($idPerso,$fonction,$idStr='',$addTrStr=false){
		$html="";
		$l=0;
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='".$fonction."']";
		$Q=$this->site->XmlParam->GetElements($Xpath);     
	    $where=str_replace("-idPerso-",$idPerso,$Q[0]->where);
	    $where=str_replace("-idStr-",$idStr,$where);
	    $sql=$Q[0]->select.$Q[0]->from.$where;
	   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	   	$req = $db->query($sql);
	   	$db->close($link);
	   	if(mysql_num_rows($req)!=0){
		   	$html.="<div >";
		   	$html.="<table  class='tabPerso' width>";	
		   	$html.="<tr>";
	   		if(!$addTrStr)
		   		$html.="<th> Service </th>";
	   		$html.="<th> Fonction </th>";
	   		$html.="<th> Bureau </th>";
	   		$html.="<th> Tel Privé </th>";
	   		$html.="<th> Tel Public </th>";
	   		$html.="<th> Fax </th>";
	   		$html.="<th> Mail </th>";
	   		$html.="</tr>";
		   	while($result=@mysql_fetch_assoc($req)){
		   		if($l==mysql_num_rows($req)-1)
		   	    	$html.="<tr class='dernier'>";
		   		else
		   			$html.="<tr>";
		   	    if(!$addTrStr)
			   		$html.="<td width='20%'>".$result['nom_str']."</td>";
		   	    $html.="<td width='20%'>".$result['nom_fonction']."</td>";
		   	    $html.="<td width='10%'>".$result['num_bureau']."</td>";
		   	    $html.="<td width='10%' >".$result['tel_public']."</td>";
		   	    $html.="<td width='10%' >".$result['tel_prive']."</td>";
		   	    $html.="<td width='10%' >".$result['fax']."</td>";
		   	    $html.="<td width='20%' >".$result['mail']."</td>";
		   	    $html.="</tr>";
		   	    $l++;
		   	}
		   	$html.="</table>";
		   	$html.="</div>";
		}
	   	return $html;
	}
function TrFonctionsStr($idFonct,$fonction,$idStr='',$addTrStr=false){
		$html="";
		$l=0;
		$req=$this->RequestSelect($fonction,array('where'=>array('idStr'=>$idStr,'idFonct'=>$idFonct)));
	   	if(mysql_num_rows($req)!=0){
		   	$html.="<div >";
		   	$html.="<table  class='tabPerso' width>";	
		   	$html.="<tr>";
	   		$html.="<th> Nom </th>";
	   		$html.="<th> Bureau </th>";
	   		$html.="<th> Tel Privé </th>";
	   		$html.="<th> Tel Public </th>";
	   		$html.="<th> Fax </th>";
	   		$html.="<th> Mail </th>";
	   		$html.="</tr>";
		   	while($result=@mysql_fetch_assoc($req)){
		   		if($l==mysql_num_rows($req)-1)
		   	    	$html.="<tr class='dernier'>";
		   		else
		   			$html.="<tr>";
		   	    $html.="<td width='20%'>".$result['nom']."&nbsp;&nbsp;".$result['prenom']."</td>";
		   	    $html.="<td width='10%'>".$result['num_bureau']."</td>";
		   	    $html.="<td width='10%' >".$result['tel_public']."</td>";
		   	    $html.="<td width='10%' >".$result['tel_prive']."</td>";
		   	    $html.="<td width='10%' >".$result['fax']."</td>";
		   	    $html.="<td width='20%' >".$result['mail']."</td>";
		   	    $html.="</tr>";
		   	    $l++;
		   	}
		   	$html.="</table>";
		   	$html.="</div>";
		}
	   	return $html;
	}
	function getListePersonnelAdmin($lettre){
		$html="<div style='margin-left:30px;margin-top:80px;'>";
	   	$html.="<ul id='annuaire'>";
	    $arrData=$this->getListePerso($lettre);
	   		while($result=mysql_fetch_assoc( $arrData)){
	   		$html.="<li  class='liPerso' style='margin-top:7px;'><a href='#' onclick='ModifPerso(this.id);' id='".$result['id_personnel']."'>".$result['nom']."&nbsp;&nbsp;".$result['prenom'] ."</a></li>";
	   		$html.=$this->TrFonctionsPreso($result['id_personnel'],'getListePersoAdmin');
		   	$html.="</li>";
	   	}
	   	$html.="</ul>";
	   	$html.="</div>";
	   	return $html;
	}
	function getListePersonnelEnsign($lettre){
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='getListePersonnelEnsign']";
	    $Q=$this->site->XmlParam->GetElements($Xpath);        
	    $where=str_replace("-MinLettre-",strtolower($lettre),$Q[0]->where);
	    $where=str_replace("-MajLettre-",$lettre,$where);
	   	$sql=$Q[0]->select.$Q[0]->from.$where;
	   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	   	$req = $db->query($sql);
	   	$db->close($link);
	   	$html.="<div style='margin-left:10px;margin-top:30px'>";
	   	$html.="<ul id='lexique' >";
	   	while($result=(mysql_fetch_assoc($req))){
	   		$UFR="";
	   		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='getEnsignUFR']";
	   	    $Q=$this->site->XmlParam->GetElements($Xpath);       
	   	    $where=str_replace("-id_enseig-",$result['id'],$Q[0]->where);
	   	    $sql=$Q[0]->select.$Q[0]->from.$where;
	   	    $db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	    $link=$db->connect();
	   	    $db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	   	    $query = $db->query($sql);
	   	    $db->close();
	   	    while($res=(mysql_fetch_assoc($query))){
	   	    	$UFR.=$res['nom_UFR']."<br/>";
	   	    }
	   		$html.="<li  class='liPerso' style='margin-top:7px;'><a href='#'>".$result['nom']."&nbsp;&nbsp;".$result['prenom'] ."</a></li>";
	   	    $html.="<div class='affTextArea'>";
	   	    $html.="<table border='0' class='tabPerso'>";
	   	    $html.="<tr>";
	   	    $html.="<td>".$UFR."</td>";
	   	    $html.="<td>".$result['nom_fonction']."</td>";
	   	    $html.="<td>".$result['bureau']."</td>";
	   	    $html.="<td>".$result['centre_recherche']."</td>";
	   	    $html.="<td>".$result['mail']."</td>";
	   	    $html.="</tr>";
	   	    $html.="</table>";
	   	  
	   	}
        $html.="</ul>";
	   	$html.="</div>";
	   	return $html;
	}
		
	function getList($type,$statut){
		$fonction="get".$type."s";
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='get".$type."s']";
	   	$Q=$this->site->XmlParam->GetElements($Xpath);
	   	$sql=$Q[0]->select.$Q[0]->from.$Q[0]->where;
	   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	   	$req = $db->query($sql);
	   	$db->close($link);
	   	$Arr='"'.$type.'":[';
	    while($res=(mysql_fetch_assoc($req))){
	   	 	$Arr.='{"id":'.$res['id_'.strtoupper($type)].',"nom":"'.$res['nom_'.$type].'" },';
   		}     
   	    $Arr.=']';
   	   return ereg_replace("},]","}]",$Arr);
	}
	function recherche($query,$type){
		if($type=='Fonction')
			$req=$this->RequestSelect('getFonctions',array('where'=>array('query'=>$query)));
		else
			$req=$this->RequestSelect('getListStr',array('where'=>array('query'=>$query,'typeStr'=>$this->getTypeStr($type))));
		if(mysql_num_rows($req)==0)
        	return false;
        $ul="<ul class='ul_suggest'>";
	   	while($res=(mysql_fetch_array($req))){
	   	 	$ul.="<li id='".$type."_".$res[0]."' onclick='SelectSuggest(this.id);'>".$res[1]."</li>";
   		}
   		$ul.="</ul>";  
   		return $ul;
	}
	function AjoutPerso($ArrData,$statut){
		$Data=json_decode($ArrData);
		// Insertion de nouveau personnel dans la table personnels
		$idPerso=$this->RequestInsert('InsertPerso',array("nom"=>$Data->ArrData->nom,
		                                                  "prenom"=>$Data->ArrData->prenom));
		$arr="{Perso:{'id':".$idPerso.",'nom':'".$Data->ArrData->nom."','prenom':'".$Data->ArrData->prenom."'}}";	

	   	return $arr;
	}
	function AjoutFonctionPersonnel($ArrData,$statut){
		$Data=json_decode($ArrData);
		$idFonct=$this->RequestInsert('InsertFonctPerso',array('idPerso'=>$Data->ArrData->id_personnel,
		                                                       'idFonct'=>$Data->ArrData->id_fonction,
															   'idStr'=>$Data->ArrData->id_str,
		                                                       'numBurea'=>$Data->ArrData->bureau,
		                                                       'telPrive'=>$Data->ArrData->tel_prive,
		                                                       'telPubli'=>$Data->ArrData->tel_public,
		                                                       'fax'=>$Data->ArrData->fax,
                                                               'mail'=>$Data->ArrData->mail,));

		
		$arr='{ArrData:{';
			$arr.='"nom_fonction":"'.$Data->ArrData->nom_fonction.'","id_fonction":"'.$Data->ArrData->id_fonction.'","id_str":"'.$Data->ArrData->id_str.'","nom_str":"'.$Data->ArrData->nom_str.'","label_str":"'.$this->getNomStr($Data->ArrData->type_str).'","bureau":"'.$Data->ArrData->bureau.'","TelPublic":'.$Data->ArrData->tel_public.',"mail":"'.$Data->ArrData->mail.'"';
		    if($Data->ArrData->tel_prive!="")
		    	$arr.=',"TelPrive":'.$Data->ArrData->tel_prive;
			if($Data->ArrData->fax!="")
		    	$arr.=',"fax":'.$Data->ArrData->fax;
		    $arr.='}}';
       return $arr;
	}
  	function getNomStr($typeStr){
  		switch ($typeStr){
  			case 1:
  				$nomStr='Service';
  		         break;
  		    case 2:
  				$nomStr='UFR';
  		         break;
  		    case 3:
  				$nomStr='Bibliotheque';
  		         break;
  		    case 4:
  				$nomStr='Departement';
  		         break; 
  		    case 5:
  				$nomStr='Ecole doctoral';
  		         break;
  		   case 6:
  				$nomStr='Equipe de recherche';
  		         break; 
  		}
  		return $nomStr;
  	}	
			
	 
	function RequestInsert($fonction,$arrValue){
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='".$fonction."']";
	   	$Q=$this->site->XmlParam->GetElements($Xpath);
        foreach($arrValue as $var=>$val){
	   		if($i==0)
        		$values=str_replace("-".$var."-",addslashes($val),$Q[0]->values);
			else
        		$values=str_replace("-".$var."-",addslashes($val),$values);
        	$i++;
        }
		$sql=$Q[0]->insert.$values;
	   	//echo $sql;
		$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	   	$req = $db->query($sql);
	   	$id=mysql_insert_id();
	   	$db->close($link);
		return $id;
	}
	function RequestSelect($fonction,$arrVar){
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='".$fonction."']";
	   	$Q=$this->site->XmlParam->GetElements($Xpath);
	    $from=$this->sqlClause($arrVar['from'],'from',$Q);
	   	$where=$this->sqlClause($arrVar['where'],'where',$Q); 	
	   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	    $sql=$Q[0]->select.$from.$where;
	    $req = $db->query($sql);
	   	$db->close($link);
		return $req; 	
	}
	function RequestDelete($fonction,$arrVar){
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='".$fonction."']";
	   	$Q=$this->site->XmlParam->GetElements($Xpath);
	   	$where=$this->sqlClause($arrVar['where'],'where',$Q); 	
	   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	    $sql=$Q[0]->delete.$Q[0]->from.$where;
	    $req = $db->query($sql);
	   	$db->close($link);
			
	}
	function sqlClause($Arr,$clause,$Q){
		$i=0;
		if($Arr){
	   	 	foreach($Arr as $var=>$val){
	   	 		if($i==0)
	   	 			 $cls=(str_replace("-".$var."-",$val,$Q[0]->$clause));
	   	 	    else
	   	 	    	$cls=(str_replace("-".$var."-",$val,$cls));
	   	 	    $i++;	
	   	 	}
	    }else{
		  $cls=$Q[0]->$clause;
	   }
	   return $cls;
	}
	function modifPerso($idPerso){
		$arrInfoPerso=mysql_fetch_assoc($this->RequestSelect('getPersoId',array('where'=>array('idPerso'=>$idPerso))));
		$html.="<fieldset  id='AjouPersoFielset'>";
		$html.=" <legend align=top> Informations personnelles </legend>  ";
		$html.="<table border='0' align='center'>";
		$html.=$this->addTr('Nom',$arrInfoPerso['id_personnel'],$arrInfoPerso['nom']);
		$html.=$this->addTr('Prénom','prenom',$arrInfoPerso['prenom']);
		$html.="</table>";
		$html.="<div style='margin-left:130px;'>";
		$html.="<button onclick='ModificationInfoPerso();' style='align:center;'>Modifier</button>";
		$html.="</div>";
		$html.="</fieldset>";
		$arrData='{infoPerso:{"idPerso":'.$idPerso.',"nom":"'.$arrInfoPerso['nom'].'","prenom":"'.$arrInfoPerso['prenom'].'", "html":"'.$html.'"},';
		$arrFonctio=$this->getFonctions(array('getListePersoAdmin'), array('where'=>array('idPerso'=>$idPerso))); 
        $arrFonctio=str_replace('],}',']}',$arrFonctio);     
        return $arrData.'"html":"'.$html.'",'.$arrFonctio.'}';
	}
	function getFonctions($arrFonc,$param){
		$arrData.='FoncServ:[';
		foreach($arrFonc as $Fonc){
			$result=$this->RequestSelect($Fonc,$param);
			 $i=0;
			while($foction=mysql_fetch_assoc($result)){
				 $html.="<div id='DivFonct".$i."' >";
				 $html.="<fieldset  id='AjouPersoFielset'  style='margin-top:10px;' >";
			 	 $html.="<legend align=top> Fonction </legend>  ";
				 $html.="<table border='0' align='center'>";
				 $html.=$this->addTr('Fonction',$foction['id_fonction'],$foction['nom_fonction'],$i);
				 $html.=$this->addTr($this->getNomStr($foction['type_str']),$foction['id_str'],$foction['nom_str'],$i);
				 $html.=$this->addTr('Bureau','bureau'.$i,$foction['num_bureau'],$i);
		         $html.=$this->addTr('Tel Privé','tel_prive'.$i,$foction['tel_prive'],$i);
				 $html.=$this->addTr('Tel Public','tel_public'.$i,$foction['tel_public'],$i);
				 $html.=$this->addTr('Fax','fax'.$i,$foction['fax'],$i);
				 $html.=$this->addTr('Mail','mail'.$i,$foction['mail'],$i);
				 $html.="</table>";
				 $html.="<div style='margin-left:130px;'>";
				 $html.="<button onclick='Modification(".$i.");'>Modifier</button>";
	             $html.="</div>";
				 $html.="</fieldset>";
				 $html.="</div>";
		         $arrData.='{"id_fonction":'.$foction['id_fonction'].',"nom_fonction":"'.$foction['nom_fonction'].'", "id_str":'.$foction['id_str'].',"nom_str'.'":"'.$foction['nom_str' ].'","label_str":"'.$this->getNomStr($foction['type_str']).'",
                    "bureau":"'.$foction['num_bureau'].'","tel_prive":'.$foction['tel_prive'].',"tel_public":'.$foction['tel_public'].',
                    "fax":'.$foction['fax'].',"mail":"'.$foction['mail'].'"},';
	             $i++;
			} 
		}
      
		$arrData.=']';
		return '"html":"'.$html.'",'.$arrData; 
	}
	function addTr($label,$id,$val,$i=''){
		$tr.="<tr valign='top'>";
		$tr.="<td class='label'> ".$label." :</td>";
	    $tr.="<td class=''>";
	    $tr.="<input type='text' value='".$val."' id='".$id."' name='".$label.$i."' class='InputClass_suggest' disabled='true'/>";
	    $tr.="</td>";
	    $tr.="</tr>";
		return $tr;
	}
	function ValideModifPersonnel($arrData){
		$Data=json_decode($arrData);
		// mettre à jour le nom et le prénom
		$this->RequestUpDate('updateInfoPerso',array('set'=>array('nomPerso'=>$Data->ArrData->nom,'pernomPerso'=>$Data->ArrData->prenom),
		                                      'where'=> array('idPerso'=>$Data->ArrData->id_personnel)));
	   	//mettre à jour la fonction 
	   	$idFonct=mysql_fetch_assoc($this->RequestSelect('getIdFonct',array('where'=>array('nomFonct'=>$Data->ArrData->nom_fonction))));
	   	//mettre a jour le service
		$idNewSer=mysql_fetch_array($this->RequestSelect('getIdStr',array('where'=>array('nomStr'=>$Data->ArrData->Nnom_str))));
		$this->RequestUpDate('updateFonct',array('set'=>array('idNStr'=>$idNewSer[0],
	                                                          'idNFonct'=>$idFonct['id_fonction'],
	                                                          'bureau'=>$Data->ArrData->bureau,
	    													  'telPrive'=>$Data->ArrData->tel_prive,
	    													  'telPublic'=>$Data->ArrData->tel_public,
	                                                          'fax'=>$Data->ArrData->fax,	
	                                                          'mail'=>$Data->ArrData->mail,
	                                                          'typeStr'=>$this->getTypeStr($Data->ArrData->Nlabel_str)),
	                                           'where'=>array('idPerso'=>$Data->ArrData->id_personnel,
	                                                          'idFonct'=>$Data->ArrData->id_fonction,
	                                                          'idStr'=>$Data->ArrData->id_str)));     
	
	     $i= $Data->ArrData->i;
		 $html.="<fieldset  id='AjouPersoFielset'  style='margin-top:10px;' >";
		 $html.="<legend align=top> Fonction </legend>  ";
		 $html.="<table border='0' align='center'>";
		 $html.=$this->addTr('Fonction',$idFonct['id_fonction'],$Data->ArrData->nom_fonction,$i);
		 $html.=$this->addTr($Data->ArrData->Nlabel_str,$idNewSer[0],$Data->ArrData->Nnom_str,$i);
		 $html.=$this->addTr('Bureau','bureau'.$i,$Data->ArrData->bureau,$i);
		 $html.=$this->addTr('Tel Privé','tel_prive'.$i,$Data->ArrData->tel_prive,$i);
		 $html.=$this->addTr('Tel Public','tel_public'.$i,$Data->ArrData->tel_public,$i);
		 $html.=$this->addTr('Fax','fax'.$i,$Data->ArrData->fax,$i);
		 $html.=$this->addTr('Mail','mail'.$i,$Data->ArrData->mail,$i);
		 $html.="</table>";
		 $html.="<div style='margin-left:130px;'>";
		 $html.="<button onclick='Modification(".$i.");'>Modifier</button>";
	     $html.="</div>";
		 $html.="</fieldset>";
		 return '{ArrData:{"html":"'.$html.'","i":'.$i.'}}';
	}                                                                                   
	function SupprimeFonctPerso($arrData){
		$Data=json_decode($arrData);
		$idStr=mysql_fetch_assoc($this->RequestSelect('getIdStr',array('where'=>array('nomStr'=>$Data->ArrData->nom_str))));
		$this->RequestDelete('deleteFonctPerso',array('where'=>array('idPerso'=>$Data->ArrData->id_personnel,
	                                                                 'idFonct'=>$Data->ArrData->id_fonction,
	                                                                 'idStr'=>$idStr['id_str'])));
	
	    $thereFonct=mysql_num_rows($this->RequestSelect('getListePersoAdmin',array('where'=>array('idPerso'=>$Data->ArrData->id_personnel))));  
	    if($thereFonct==0){
	    	$this->RequestDelete('deletePerso',array('where'=>array('idPerso'=>$Data->ArrData->id_personnel)));
	    }
	    return '{ArrData:{"thereFonct":"'.$thereFonct.'",i:'.$Data->ArrData->i.'}}';
	}                                                         
	function RequestUpDate($fonction,$arrVar){
		$Xpath="/XmlParams/XmlParam/Querys/Query[@fonction='".$fonction."']";
	   	$Q=$this->site->XmlParam->GetElements($Xpath);
	   	$set=$this->sqlClause($arrVar['set'],'set',$Q);
	    $where=$this->sqlClause($arrVar['where'],'where',$Q); 	
	   	$db = new mysql ($this->BDD["SQL_HOST"], $this->BDD["SQL_LOGIN"], $this->BDD["SQL_PWD"], $this->BDD["SQL_DB"]);
	   	$link=$db->connect();
	   	$db->query("SET CHARACTER SET 'utf8';", $link)or die(mysql_error());
	   	$sql=$Q[0]->update.$set.$where;
	   	$req = $db->query($sql);
	   	$db->close($link);
	}
	function getTypeStr($nomStr){
		switch ($nomStr){
  			case 'Service':
  				$typeStr=1;
  		         break;
  		    case 'UFR':
  				$typeStr=2;
  		         break;
  		    case 'Bibliotheque':
  				$typeStr=3;
  		         break;
  		    case 'Departement':
  				$typeStr=4;
  		         break; 
  		    case 'Ecole doctoral':
  				$typeStr=5;
  		         break;
  		   case 'Equipe de recherche':
  				$typeStr=6;
  		         break; 
  		}
  		return $typeStr;
	}
	function getStr($Str){
		$arrServ=$this->RequestSelect('getStr',array('where'=>array('typeStr'=>$this->getTypeStr($Str))));
		$ul.='<ul id="AnnuaireListServ" >';
		while($service=mysql_fetch_assoc($arrServ)){
		 	$ul.='<li id="'.$service['id_str'].'" onclick="getListPersoStr(this.id);">';
		 	$ul.='<a  href="#" >'.$service['nom_str'].'</a>';  		       				   	 
		 	$ul.='</li>';			   		    			 	 		   	
		}
		$ul.='</ul>';
		return $ul;
	}
	function getListPersoStr($idStr,$Str){
		$html='';
		$arrFonct=$this->RequestSelect('getFonctStr',array('where'=>array('idStr'=>$idStr)));
	   	$html="<div style='margin-left:30px;margin-top:80px;'>";
	   	$html.="<ul id='annuaire'>";
		while($Fonct=mysql_fetch_assoc( $arrFonct)){
			$html.="<li  class='liPerso'><a href='#'  id='".$Fonct['id_fonction']."'>".$Fonct['nom_fonction']."</a></li>";
	   		$html.=$this->TrFonctionsStr($Fonct['id_fonction'],'getStrFonctInfo',$idStr,true);
		   	$html.="</li>";
	   	}
	   	$html.="</ul>";
	   	$html.="</div>";
	   return $html;
	}
	
	function ValiderAjoutStr($newStr,$Str){
       return  $this->RequestInsert('InsertStr',array('nomStr'=>$newStr,'typeStr'=>$this->getTypeStr($Str))); 	 
	}
}
?>